package com.dtx.builder;


/**
 * 由于TextBuilder和HTMLBuilder都是Builder的子类,因此Director仅仅使用Builder
 * 的方法即可编写文档。也就是说,Director并不关系实际编写文档的到底是TextBuilder还是HTMLBuilder
 * 正因为如此,我们必须在Builder中声明足够多的方法,已实现编写文档的功能,但并不包括TextBuilder和HTMLBuilder
 * 中特有的方法。
 */
public class BuildMain {

    public static void main(String[] args) {
        args = new String[]{"html"};
        if (args.length != 1) {
            usage();
            System.exit(0);
        }

        if (args[0].equals("plain")) {
            TextBuilder textBuilder = new TextBuilder();
            Director director = new Director(textBuilder);
            director.construct();
            String result = textBuilder.getResult();
            System.out.println(result);
        }else if(args[0].equals("html")){
            HTMLBuilder htmlBuilder = new HTMLBuilder();
            Director director = new Director(htmlBuilder);
            director.construct();
            String fileName = htmlBuilder.getResult();
            System.out.println(fileName + "文件编写完成。");
        }else {
            usage();
            System.exit(0);
        }

    }

    public static void usage(){
        System.out.println("Usage: java Main plain        编写纯文本文档");
        System.out.println("Usage: java Main html         编写HTML文档");
    }
}
